This invention relates to a method and apparatus for handling translucency in rendering of graphic images composed of a plurality of triangular image primitives.
Translucency techniques are applied in 3D graphics not only to provide images of translucent objects, when anti-aliasing is difficult where such objects overlap, but also to allow smooth transition from one model to another to allow substantial changes in model size; the application of fade level of detail is applied in flight simulators when objects recede rapidly.
In 3D graphics a translucent object allows objects behind it to be visible through it in attenuated form, while an opaque object obscures any other object behind it. Translucency is typically monochrome, i.e. there is one alpha component common to red, green and blue colour components; if each colour component has its own alpha component, then the well known effects of subtractive colour mixing apply at object overlaps.
One model of translucency is the small hole model. If a translucent object is made by peppering a coloured opaque object with a myriad of holes so small as to be invisible to the human eye, objects behind the translucent object are visible through the holes. Translucency can be defined as the area occupied by holes per unit area of the objects surface.
Consider looking through a succession of overlapping translucent objects, each with a translucency of 0.25, using the above small hole model. The nearest object has its colour attenuated by 0.75, because only 0.75 of the object surface area reflects light and the remaining 0.25 comprises holes. The second nearest object has its colour attenuated by (0.25*0.75); only 0.25 of the second object""s surface is visible through the holes in the first object, and of that surface only 0.75 reflects light. This is shown in Table 1 below for objects of equal translucency.
If the objects are of differing translucencies, the position is that illustrated in Table 2 below.
Assume that each pixel fragment fully covers the pixel; to determine the final colour of a given pixel on the screen, pixel fragments are rendered in front to back order, each being textured and shaded independently. The colour of each pixel fragment is attenuated to account for the effects of translucent fragments in front of it, the amount of attenuation being calculated after the example of Table 2 above.
It is apparent from Tables 1 and 2 that the sum of the attenuations (cumulative attenuation) approaches unity; indeed the sum of attenuations must be unity to obtain the final pixel colour. For a finite number of translucent surfaces at a given pixel, assume there is an opaque background, for example the sky, attenuate its colour by unity minus the sum of the attenuations (thereby forcing the final sum of attenuations to unity) and add the result to the final pixel colour.
Typically, translucency is assigned a numeric value which can be considered to lie in the range 0.0 to 1.0; this range might be mapped to the integers 0 to 256 in a hardware implementation.
The value of 256 is inconvenient, requiring 9 bits to encode 257 values, when 8 bits suffice for values in the range 0 to 255. Some systems map the range 0.0 to 1.0 onto the range 0 to 255, but this makes it awkward to represent values such as 0.25, 0.5 and 0.75. Some systems map the range 0.0 onto the range 0 to 256, and then represent the value 256 as 255.
By convention the term xe2x80x9ctranslucencyxe2x80x9d maps opaque objects to the value 0.0 and transparent objects to the value 1.0, because translucency increases over the range. The term xe2x80x9copacityxe2x80x9d is applied when translucent objects are mapped to the value 0.0 and opaque objects to the value 1.0, because opacity increases over the range. The term xe2x80x9calphaxe2x80x9d is used to refer to the value irrespective of whether it is interpreted as translucency or opacity.
In real time consumer 3D graphics, there are three types of translucency; conventional, texture, and screendoor.
Conventional translucency is applied to an entire object, mesh or face, and is typically represented by eight bits for 256 different levels of translucency. Conventional translucency has a cumulative attenuation effect when objects are viewed through several layers or translucency.
If an increasing amount of conventional translucency is applied to a VRML model of an object, the expectation is that the object will fade away; in practice unexpected dark regions may occur, because real time 3D graphics models make use of intersecting faces; for example the mesh representing a character""s leg will penetrate the mesh representing the character""s body to prevent gaps and cracks appearing at the join under animation; rather than trimming the intersecting polygons to fit, the xe2x80x9cspare partsxe2x80x9d of the polygons are just left in the knowledge that in normal use they remain hidden behind an opaque surface of the intersecting polygon. However when the technique of translucency is applied, the intersection appears dark because there are more translucent surfaces than expected.
Screendoor translucency is a technique in which an object is literally peppered with holes, e.g. by not drawing certain pixels in the object. The more pixels that are omitted, the greater the apparent translucency. For example a translucency of 0.5 is simulated by drawing every other pixel, but a regular pattern of missing pixels must be avoided because it can become annoyingly apparent to a viewer. This need to avoid a regular pattern limits the number of discreet levels of translucency which can be achieved by using screendoor translucency.
For the typical application of translucency in fade level of detail, conventional translucency is unsuitable because of the unexpected dark regions at intersections, so screendoor translucency is preferred.
In U.S. Pat. No. 5,864,342 Microsoft Corporation, a method of rendering graphical objects which may be translucent is disclosed in which geometric primitives of models are divided into xe2x80x9cchunksxe2x80x9d and pixel fragments for each chunk are generated then resolved. Texture mapping and filtering occurs prior to anti-aliasing the texture-mapped primitive, but there is no reduction of the number of attributes to be calculated.
In co-pending application WO99/06957 an invention is disclosed in which pixels from triangular image primitives are provided with inside flags which are used to determine contributions from values, such as colour or texture, stored at each vertex of the triangle, to give attribute values to each pixel. Pixel attribute values from all triangles jointly determine an output colour for each pixel.
The present invention is an improvement of that technique which allows translucency in a 3D graphics system to be handled.
According to the present invention, there is provided an image processing method for rendering a two dimensional pixel image from a plurality of triangular image primitives to be projected onto an image plane, in which per-pixel attribute values, derived by interpolation from values held for the triangle vertices, are mapped onto respective pixels within the projected triangular primitives, in which, for each triangle:
prior to projection, the triangle is parameterised with a respective two-dimensional co-ordinate system with the co-ordinate axes (s,t) concurrent with respective edges of the triangle and the origin coincident with the vertex between said edges;
during projection, a generalised interpolation function is applied in terms of the parameterising co-ordinate system, determining parameter values at positions within the triangle in terms of the two-dimensional co-ordinate system;
following projection, the determined parameter values at positions within the triangle determine contributions from the stored values for one or more attributes at each vertex, to give attribute values at each pixel;
characterised in that said parameter values at positions within the triangle are translucency values.
Also according to the invention there is provided processing apparatus configured to render a two dimensional pixel image from data defining a plurality of triangular image primitives to be projected onto an image plane, the apparatus including interpolation means arranged to derive per-pixel attribute values from values held for the triangle vertices, and data handling means arranged to map said per-pixel attribute values onto respective pixels within the projected triangular primitives:
calculation means coupled to receive the data defining said triangular primitives, prior to projection, and arranged to parameterise each triangle with a respective two-dimensional co-ordinate system with the co-ordinate axes (s,t) concurrent with respective edges of the triangle and the origin coincident with the vertex between said edges;
projection means operable to apply a generalised interpolation function to each triangle and in terms of the parameterising co-ordinate system, such as to derive parameter values at positions within a triangle in terms of said two dimensional co-ordinate system; and
pixel shading means configured to derive, from said determined parameter values at positions within the triangle, contributions from said stored values for one or more attributes at each vertex, such as to give attribute values at each pixel, and to combine per pixel attribute values from all triangles and provide a per pixel colour value,
characterised in that the apparatus further comprises means to characterise a pixel as a translucent pixel, and when a translucent pixel overlays another pixel, to provide a per pixel colour value derived from the colour of the foremost translucent pixel.
In the inventive method, a number of flags inside each triangle are supplied as main attributes indicating whether pixel fragments are translucent or opaque; this allows the fragments to be correctly inserted into the pixel fragment buffer, because the actual translucency is not known until a texturing or shading step has been performed.
When the type of translucency to be applied by the inventive method is screendoor translucency, then some of the inside flags of a pixel fragment are masked off when it is proposed to the pixel fragment buffer. Preferably screendoor translucency is encoded to a limited number of translucency levels, (e.g. 8 levels, using 3 bits), and the levels are converted by use of a look-up table to the required number (e.g. 32) of bit masks.
Conventional translucency values could be made available as main attributes, but would require an additional number of bits to hold the main attributes. Neither texture translucency nor screendoor translucency can be a main attribute because they are both applied per pixel and not per face. For conventional translucency, texture translucency and e.g. eight levels of screendoor translucency in the inventive method, it is necessary to provide only four extra bits per main attribute and four extra bits per pixel fragment, so the pixel fragment buffer can still be provided relatively cheaply.
During the rendering process in the inventive method, pixel fragments are rendered from the front of an object to the back of an object; the alpha values of rendered translucent pixel fragments are accumulated until their sum exceeds unity; a correction is then made as a function of the colour and alpha of the last pixel fragment such that the summed alpha equals unity.
As each translucent fragment is rendered, its colour is attenuated in proportion to the product of several alpha values, such as for conventional translucency or texture translucency.